package com.hx.learn.mybatis.web;

import com.hx.learn.mybatis.mapper.PostMapper;
import com.hx.learn.mybatis.mapper.TeacherMapper;
import com.hx.learn.mybatis.mapper.UserMapper;
import com.hx.learn.mybatis.model.Post;
import com.hx.learn.mybatis.model.Teacher;
import com.hx.learn.mybatis.model.User;
import javafx.geometry.Pos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author jxlgcmh
 * @date 2019-09-26 15:12
 */
@RestController
public class WebController {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private PostMapper postMapper;

    @Autowired
    private TeacherMapper teacherMapper;
    /**
     * 一对多练习
     * @param id
     * @return
     */
    @RequestMapping("user/get/{id}")
    public User findById(@PathVariable Integer id) {
        return userMapper.selectById(id);
    }

    @RequestMapping("post/get/{userId}")
    public List<Post> findByUserId(@PathVariable Integer userId){
        return postMapper.selectByUserId(userId);
    }

    @RequestMapping("teacher/get/{teacherId}")
    public Teacher findTeacherById(@PathVariable Integer teacherId ){
        return teacherMapper.selectById(teacherId);
    }

    @RequestMapping("post/get2/{id}")
    public Map findByUserIdResultAsMap(@PathVariable Integer id){
        return postMapper.selectResultAsMap(id);
    }

}
